package com.jx.common.util;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * 日期工具类
 */
public class DateUtil {

    public static final String YYYY_MM_DD = "yyyy-MM-dd";

    /**
     * 获取一月内的天数
     */
    public static List<String> getDayListWithinOneMonth() {
        List<String> list = new ArrayList<>();
        LocalDate endDate = LocalDate.now();
        LocalDate startDate = endDate.plusMonths(-1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM_DD);
        for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
            list.add(date.format(formatter));
        }
        return list;
    }

    /**
     * 获取一周内的天数
     */
    public static List<String> getDayListWithinOneWeek() {
        List<String> list = new ArrayList<>();
        LocalDate endDate = LocalDate.now();
        LocalDate startDate = endDate.plusDays(-7);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM_DD);
        for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
            list.add(date.format(formatter));
        }
        return list;
    }

}
